﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.Fashionzoomer.BLL;
using Pheonix.CodeLibrary;

public partial class control_Newsletter : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        newsletterEmail.Attributes.Add("onclick", "javascript:this.value='';javascript:this.style.color='#cc0000';");
        subscribeButton.ImageUrl = "~/App_Themes/" + Page.StyleSheetTheme + "/image/infoBox_10.jpg";
        unsubscribeButton.ImageUrl = "~/App_Themes/" + Page.StyleSheetTheme + "/image/infoBox_12.jpg";
    }

    protected void subscribeButton_Click(object sender, EventArgs e)
    {
        ActionResult result = NewsletterManager.AddEmailToNewsletterList(newsletterEmail.Text);
        if (result.ResultType == ActionResultType.Succeed)
            responseMessage.Text = "Successfully subscribed!";
        else if (result.ResultType == ActionResultType.InvalidOperation)
            responseMessage.Text = "Invalid email entered";
        else
            responseMessage.Text = "Server error, try latter";

    }

    protected void unsubscribeButton_Click(object sender, EventArgs e)
    {
        ActionResult result = NewsletterManager.RemoveEmailFromNewsletterList(newsletterEmail.Text);

        if (result.ResultType == ActionResultType.Succeed)
            responseMessage.Text = "Successfully unsubscribed!";
        else if (result.ResultType == ActionResultType.InvalidOperation)
            responseMessage.Text = "Invalid email entered";
        else
            responseMessage.Text = "Server error, try latter";
    }
}
